﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DAL;
using Models;
using System.IO;
using System.Drawing.Imaging;

namespace 包覆门.OrderManager
{
    public partial class DetailOrderEditing : Form
    {
        #region 构造方法
        public DetailOrderEditing()
        {
            InitializeComponent();
        }
        #endregion 构造方法

        #region 自定义字段

        public string EditingId { get; set; }//编辑时主键
        public bool IsNew { get; set; }//是否新增表标志
        public bool IsCopy { get; set; }
        public string Danhao { get; set; }//从主单号中带过来
        private Dictionary<int, string> dic = new Dictionary<int, string>();//装饰条和门型区分类型字典
        private OrderDAL dal = new OrderDAL();//数据业务处理
        private DictionaryTypeDAL dicType = new DictionaryTypeDAL();//订单类型字典公共类 
        private DataTable dtMxbh = new DataTable();//门型字典
        private DataTable dtGlassType = new DataTable();//玻璃字典
        private DataTable dtXbzjColor = new DataTable();//芯板做旧颜色
        private DataTable dtZsxt = new DataTable();//装饰线条
        private DataTable dtZsxtZj = new DataTable();//装饰线条做旧
        private DataTable dtPackage = new DataTable();//包装类型
        private DataTable otherDetail = new DataTable();//另加装饰下拉库
        private string xbColorDB = string.Empty;
        private bool xbColorFlag = false;

        #endregion 自定义字段

        //加载数据
        private void DetailOrderEditing_Load(object sender, EventArgs e)
        {
            //MessageBox.Show("加载");
            //加载预置字典
            LoadData();
            
            if (IsNew) {
                xbColorFlag = true;
                this.tbDanhao.Text = Danhao;
                SetLabelState(true);
                //设置控件状态
                SetControlState(true);
            } else {
                xbColorFlag = false;
                DetailOrder dlo = dal.GetDetailById(EditingId);
                this.tbDanhao.Text = dlo.Danhao;
                this.cbType.SelectedValue = dlo.Zslb;
                
                if (dlo.Zslb == 0)
                {
                    this.label9.Text = "边框颜色：";
                    this.cbMxbh.Text = dlo.MxbhSm;
                    this.cbMxbh.SelectedValue = dlo.Mxbh;
                    this.tbKxbh.Text = dlo.Kxbh;
                    this.tbXbmc.Text = dlo.Xbmc;
                    this.tbMenxingprice.Text = dlo.Price;
                    this.tbSpecial.Text = dlo.SpecialName;
                    this.tbAddPrice.Text = dlo.SpecialPrice.ToString();
                    this.tbglass.Text = dlo.Glass.ToString();
                    this.tbIsSoft.Text = dlo.IsSoft.ToString();
                    this.tbIsSpecial.Text = dlo.IsSpecial.ToString();
                    this.cbWenlu.Text = dlo.Wenlu;
                    this.cbPjfs.Text = dlo.Pjfs;
                    if (dlo.Glass.ToString().Equals("1")) {
                        this.gbGlass.Enabled = true;
                        this.cbGlassType.Enabled = true;
                    }
                    foreach (RadioButton rb in this.gbGlass.Controls) {
                        if (dlo.IsGlass.ToString().Equals(rb.Tag.ToString())) { 
                            rb.Checked=true;
                            break;
                        }
                    }
                    if (!string.IsNullOrWhiteSpace(dlo.GlassType))
                        this.cbGlassType.Text = dlo.GlassType;
                    if (!string.IsNullOrWhiteSpace(dlo.GlassId))
                        this.cbGlassType.SelectedValue = dlo.GlassId;
                    this.tbGao.Text = dlo.Gao;
                   // this.tbHou.Text = dlo.Hou;
                    this.tbKuan.Text = dlo.Kuan;
                  //  this.tbXbxs.Text = dlo.Xbxs;
                    foreach (RadioButton rb in this.gbZh.Controls) {
                        if (rb.Tag.ToString().Equals(dlo.IsZh.ToString())) {
                            rb.Checked = true;
                            break;
                        }
                    }
                    if (dlo.IsZh.ToString().Equals("2")) {
                        //this.tbDownHeight.Text = dlo.xbDownHeight;
                        this.tbxbtop.Text = dlo.XbTop;
                        this.tbTopHeight.Text = dlo.XbTop;
                    }
                    this.cbDirection.Text = dlo.Direction;
                    foreach (RadioButton rb in this.gbXbzj.Controls) {
                        if (rb.Tag.ToString().Equals(dlo.IsOld.ToString())) {
                            rb.Checked = true;
                            break;
                        }
                    }
                    this.cbXbzjColor.Text = dlo.OldColor;
                    this.cbpackage.SelectedValue = dlo.PackageId;//后期增加包装类别

                    //装饰另加装饰颜色
                    if (Convert.ToInt32(dlo.IsOther)==1) {
                        this.lbOther.Visible = true;
                        this.lbOtherRed.Visible = true;
                        this.cbOther.Visible = true;
                        DataTable dectable = dicType.GetOtherName(dlo.Kxbh);
                        if (dectable == null || dectable.Rows.Count <= 0)
                        {
                            this.lbOther.Visible = false;
                            this.lbOtherRed.Visible = false;
                            this.lbOther.Text = "";
                            this.cbOther.Visible = false;
                            this.cbOther.DataSource = null;
                        }
                        else
                        {
                            object o = dectable.Rows[0]["decname"];
                            if (o == DBNull.Value || o == null)
                            {
                                this.lbOtherRed.Visible = false;
                                this.lbOther.Visible = false;
                                this.lbOther.Text = "";
                                this.cbOther.Visible = false;
                                this.cbOther.DataSource = null;
                            }
                            else
                            {
                                this.lbOtherRed.Visible = true;
                                this.lbOther.Visible = true;
                                this.lbOther.Text = o + ":";
                                this.cbOther.Visible = true;
                                otherDetail = dicType.GetOtherDetail(dlo.Kxbh, dectable.Rows[0]["oid"].ToString());
                                otherDetail.Rows.InsertAt(otherDetail.NewRow(), 0);
                                this.cbOther.DataSource = otherDetail;
                                this.cbOther.Text = dlo.DecName;
                                if (string.IsNullOrWhiteSpace(dlo.DecId))
                                {
                                    
                                }
                                else
                                {
                                    this.cbOther.SelectedValue = dlo.DecId;
                                }
                            }
                        }
                    }
                    xbColorDB = dlo.XbColor;
                    
                    this.tbxbcolor.Text = dlo.XbColor;
                    //设置控件状态
                    SetControlState(true);
                    SetLabelState(true);
                    if ("PB-PB01".Equals(dlo.Mxbh))
                    {
                        this.lbxbcolor.Visible = false;
                        this.lbxbbq.Visible = false;
                        this.tbxbcolor.Visible = false;
                    }
                    else
                    {
                        this.lbxbcolor.Visible = true;
                        this.lbxbbq.Visible = true;
                        this.tbxbcolor.Visible = true;
                    }
                    
                }
                else {
                    //设置控件状态
                    this.label9.Text = "表面PVC颜色：";
                    SetLabelState(false);
                    SetControlState(false);
                    this.cbZsxt.Text = dlo.MxbhSm;
                    this.cbZsxt.SelectedValue = dlo.Mxbh;
                    this.tbCd.Text = dlo.Gao;
                    this.cbColor.Text = dlo.Color;
                    this.cbColor.SelectedValue = dlo.ColorId;
                    foreach (RadioButton rb in this.gbIsold.Controls)
                    {
                        if (rb.Tag.ToString().Equals(dlo.IsOld.ToString())) {
                            rb.Checked = true;
                            break;
                        }
                    }
                    if (dlo.IsOld == 1) {
                        this.cbXbzjColor.Enabled = true;
                        this.cbXbzjColor.Text = dlo.OldColor;
                        this.cbXbzjColor.SelectedValue = dlo.OldColorId;
                    }
                    
                }
                this.tbIszt.Text = dlo.IsZt.ToString();
                this.cbColor.Text = dlo.Color;
                this.tbNum.Text = dlo.Num;
                this.tbOtherPrice.Text = dlo.OtherPrice;
                this.tbOtherDesc.Text = dlo.OtherSm;
                this.tbBzbz.Text = dlo.Bzbz;
            }
        }

       

        #region 按钮事件
        //保存
        private void btnSave_Click(object sender, EventArgs e)
        {
            //所有业务从本地处理
            string zslb = this.cbType.SelectedValue == null ? "" : this.cbType.SelectedValue.ToString();//获取类别数据
            //先保存数据
            DetailOrder dlo = new DetailOrder();
            dlo.Danhao = this.tbDanhao.Text;
            dlo.Zslb = Convert.ToInt32(zslb);
            if (zslb.Equals("0"))
            {
                //1、门型
                dlo.Xbxs = "";
                dlo.Mxbh = this.cbMxbh.SelectedValue==null?"":this.cbMxbh.SelectedValue.ToString();
                dlo.MxbhSm = this.cbMxbh.Text;
                dlo.Kxbh = this.tbKxbh.Text;
                dlo.Xbmc = this.tbXbmc.Text;
                dlo.Gao = this.tbGao.Text;//高度
                dlo.Price = this.tbMenxingprice.Text.Trim();
                if (!string.IsNullOrWhiteSpace(tbglass.Text))
                {
                    dlo.Glass = Convert.ToInt32(this.tbglass.Text.Trim());
                }
                foreach (RadioButton rb in this.gbGlass.Controls)
                {
                    if (rb.Checked)
                    {
                        dlo.IsGlass = Convert.ToInt32(rb.Tag);
                        break;
                    }
                }
                
                if (dlo.IsGlass == 1||dlo.Glass==1)
                {
                    dlo.GlassType = this.cbGlassType.Text;
                    dlo.GlassId = this.cbGlassType.SelectedValue.ToString();
                    dlo.Xbxs = dlo.Xbxs + this.cbGlassType.Text + ";\r\n";
                }
                dlo.Pjfs = this.cbPjfs.Text;
                dlo.Kuan = this.tbKuan.Text;
                //dlo.Hou = this.tbHou.Text;
                //dlo.Xbxs = this.tbXbxs.Text;
                dlo.Color = this.cbColor.Text;
                dlo.ColorId = this.cbColor.SelectedValue == null ? "" : this.cbColor.SelectedValue.ToString();
                 
                foreach (RadioButton rb in this.gbZh.Controls)
                {
                    if (rb.Checked)
                    {
                        dlo.IsZh = Convert.ToInt32(rb.Tag);
                        break;
                    }
                }
                //新增芯板高度
                if (dlo.IsZh == 2) {
                    //dlo.xbDownHeight = this.tbDownHeight.Text.Trim();
                    dlo.XbTop = this.tbTopHeight.Text.Trim();
                }
                dlo.Direction = this.cbDirection.Text;
                foreach (RadioButton rb in this.gbXbzj.Controls)
                {
                    if (rb.Checked)
                    {
                        dlo.IsOld = Convert.ToInt32(rb.Tag);
                    }
                }
               
                if (!string.IsNullOrWhiteSpace(this.tbIsSoft.Text.Trim()))
                {
                    if ("1".Equals(this.tbIsSoft.Text.Trim())) //判断芯板是否软包
                    {
                        dlo.Xbxs = dlo.Xbxs + "芯板软包;\r\n";
                    }
                }
                if (dlo.IsZh == 1) {
                    dlo.Xbxs = dlo.Xbxs + "中横;\r\n";
                }
                else if (dlo.IsZh == 2) {
                   // dlo.XbTopHeight = this.tbTopHeight.Text;
                    dlo.Xbxs = dlo.Xbxs + "中横(自定义);\r\n";
                }
                if ("1".Equals(this.tbIsSpecial.Text.Trim())) //判断是否另付费
                {
                    dlo.IsSpecial = 1;
                    dlo.SpecialName = this.tbSpecial.Text.Trim();
                    dlo.SpecialPrice = Convert.ToDecimal(this.tbAddPrice.Text.Trim());
                }
                else
                {
                    dlo.IsSpecial = 0;
                    dlo.SpecialName = "";
                    dlo.SpecialPrice = 0;
                }
                if (dlo.IsOld == 1) {
                    dlo.OldColorId = this.cbXbzjColor.SelectedValue.ToString();
                    dlo.OldColor = this.cbXbzjColor.Text;
                    dlo.Xbxs = dlo.Xbxs + this.cbXbzjColor.Text + ";\r\n";
                }
                if (!string.IsNullOrWhiteSpace(this.cbWenlu.Text))
                {
                    dlo.Wenlu = this.cbWenlu.Text.Trim();
                    dlo.Xbxs = dlo.Xbxs + this.cbWenlu.Text + ";\r\n";
                }
                if (!string.IsNullOrWhiteSpace(this.tbHingeType.Text)) {
                    dlo.HingeType = this.tbHingeType.Text.Trim();
                    dlo.Xbxs = dlo.Xbxs + this.tbHingeType.Text + ";\r\n";
                }
                //后期增加包装类别
                dlo.PackageId = this.cbpackage.SelectedValue == null ? "" : this.cbpackage.SelectedValue.ToString();
                dlo.PackageName = this.cbpackage.Text.Trim();
                dlo.PackagePrice = this.tbpackageprice.Text.Trim();
                //另加装饰选项
                if (this.lbOther.Visible&&cbOther.Visible) {
                    dlo.IsOther = 1;
                    dlo.DecName = this.cbOther.Text;
                    dlo.DecId = this.cbOther.SelectedValue == null ? "" : this.cbOther.SelectedValue.ToString();
                    if (!string.IsNullOrWhiteSpace(dlo.DecName)) {
                        dlo.ParentName = lbOther.Text;
                    }
                }
                //芯板颜色新增到芯板备注中
                if (!string.IsNullOrWhiteSpace(this.tbxbcolor.Text) && !"PB-PB01".Equals(dlo.Mxbh))
                {
                    dlo.XbColor = this.tbxbcolor.Text.Trim();
                    dlo.Xbxs = dlo.Xbxs +"芯板颜色：" +this.tbxbcolor.Text + ";";
                }
            }
            else
            {
                //2、装饰线条
                dlo.Mxbh = this.cbZsxt.SelectedValue == null ? "" : this.cbZsxt.SelectedValue.ToString();
                dlo.MxbhSm = this.cbZsxt.Text;
                dlo.Xbmc = this.cbZsxt.Text;
                dlo.Gao = this.tbCd.Text;//高度
                dlo.Color = this.cbColor.Text;
                dlo.ColorId = this.cbColor.SelectedValue == null ? "" : this.cbColor.SelectedValue.ToString();

                foreach (RadioButton rb in this.gbIsold.Controls)
                {
                    if (rb.Checked)
                    {
                        dlo.IsOld = Convert.ToInt32(rb.Tag);
                    }
                }
                dlo.IsZt = Convert.ToInt32(this.tbIszt.Text);//是否柱头
                if (dlo.IsZt == 1) //柱头长度
                {
                    dlo.Ztcd = this.tbCd.Text;
                }
                if (dlo.IsOld==1) {
                    dlo.OldColorId = this.cbXbzjColor.SelectedValue == null ? "" : this.cbXbzjColor.SelectedValue.ToString();
                    dlo.OldColor = this.cbXbzjColor.Text;
                    dlo.Xbxs = dlo.Xbxs + this.cbXbzjColor.Text + ";\r\n";
                }
            }
           
            //dlo.Pjfs = this.cbPjfs.Text;
            dlo.Num = this.tbNum.Text;
            dlo.OtherSm = this.tbOtherDesc.Text;
            dlo.OtherPrice = this.tbOtherPrice.Text;
            //if (!this.tbBzbz.Text.Equals("无"))
            dlo.Bzbz = this.tbBzbz.Text;
            //dlo.Bzbz += this.cbpackage.Text + ";";
            if (IsNew)
            {
                //条形码 2.0
                object o = dal.GetDetailXh(dlo.Danhao);
                if (o == null)
                {
                    dlo.Xh = 1;
                }
                else
                {
                    dlo.Xh = Int32.Parse(o.ToString()) + 1;
                }
                if (zslb.Equals("0"))
                {
                    //门型操作步骤
                    //1、验证是否填写必填项
                    if (!ValidateMxData(dlo)) return;
                    // * 填写单价
                    //DataRow[] drs = dtMxbh.Select("mxbh='" + dlo.Mxbh + "'");
                    //if (drs.Length == 1)
                    //{
                    //    dlo.Price = drs[0]["price"].ToString();
                    //}
                    //else
                    //{
                    //    throw new Exception("此门型在库中没有");
                    //}
                    //2、根据公式计算数据
                    dlo=HandleMxOrder(dlo);
                   
                    
                    //保存数据 
                    int result = dal.SaveDetailOrder(dlo);
                    //long result = dal.SaveDetailOrderId(dlo);//2.0
                    if (result ==1 )
                    {
                        MessageBox.Show("保存成功");
                        DialogResult = DialogResult.OK;
                        //生成条形码 V2.0
                        //1、文件夹路径 
                        //string path = ".\\" + dlo.Danhao;
                        //2、生成条形码
                        // bool fl = GenerateCode(dlo, path,result);
                        //if (fl)
                        //{

                        //    MessageBox.Show("保存成功");
                        //    DialogResult = DialogResult.OK;
                        //}
                        //else 
                        //{
                        //    MessageBox.Show("保存失败");
                        //    DialogResult = DialogResult.No;
                        //}
                    }
                    else {

                        MessageBox.Show("保存失败");
                        DialogResult = DialogResult.No;
                    }
                    
                }
                else
                {
                    //装饰线条
                    //1、先验证是否填写必填项
                    if (!ValidateZsxtData(dlo)) return;
                    dlo = HandleZsxtOrder(dlo);
                    int result = dal.SaveDetailOrder(dlo);
                    //long result = dal.SaveDetailOrderId(dlo); //2.0
                    if (result == 1)
                    {
                        MessageBox.Show("保存成功");
                        DialogResult = DialogResult.OK;
                        //生成条形码 2.0
                        //1、文件夹路径
                        //string path = ".\\" + dlo.Danhao;
                        ////2、生成条形码
                        //bool fl = GenerateCode(dlo, path, result);
                        //if (fl)
                        //{

                        //    MessageBox.Show("保存成功");
                        //    DialogResult = DialogResult.OK;
                        //}
                        //else
                        //{
                        //    MessageBox.Show("保存失败");
                        //    DialogResult = DialogResult.No;
                        //}
                    }
                    else
                    {

                        MessageBox.Show("保存失败");
                        DialogResult = DialogResult.No;
                    }
                }
            }
            else 
            {
                if (IsCopy) {
                    //条形码 2.0
                    object o = dal.GetDetailXh(dlo.Danhao);
                    if (o == null)
                    {
                        dlo.Xh = 1;
                    }
                    else
                    {
                        dlo.Xh = Int32.Parse(o.ToString()) + 1;
                    }
                    if (zslb.Equals("0"))
                    {
                        //门型操作步骤
                        //1、验证是否填写必填项
                        if (!ValidateMxData(dlo)) return;
                        //2、根据公式计算数据
                        dlo = HandleMxOrder(dlo);
                        //保存数据 
                        int result = dal.SaveDetailOrder(dlo);
                        if (result == 1)
                        {
                            MessageBox.Show("保存成功");
                            DialogResult = DialogResult.OK;
                        }
                        else
                        {

                            MessageBox.Show("保存失败");
                            DialogResult = DialogResult.No;
                        }

                    }
                    else
                    {
                        //装饰线条
                        //1、先验证是否填写必填项
                        if (!ValidateZsxtData(dlo)) return;
                        dlo = HandleZsxtOrder(dlo);
                        int result = dal.SaveDetailOrder(dlo);
                        //long result = dal.SaveDetailOrderId(dlo); //2.0
                        if (result == 1)
                        {
                            MessageBox.Show("保存成功");
                            DialogResult = DialogResult.OK;
                            
                        }
                        else
                        {
                            MessageBox.Show("保存失败");
                            DialogResult = DialogResult.No;
                        }
                    }
                }
                else 
                {
                    dlo.Did = Convert.ToInt32(EditingId);
                    if (zslb.Equals("0"))
                    {
                        //门型操作步骤
                        //1、验证是否填写必填项
                        if (!ValidateMxData(dlo)) return;
                        // * 填写单价
                        //DataRow[] drs = dtMxbh.Select("mxbh='" + dlo.Mxbh + "'");
                        //if (drs.Length == 1)
                        //{
                        //    dlo.Price = drs[0]["price"].ToString();
                        //}
                        //else
                        //{
                        //    throw new Exception("此门型在库中没有");
                        //}
                        //2、根据公式计算数据
                        dlo = HandleMxOrder(dlo);
                        //保存数据
                        int result = dal.UpdateDetailOrder(dlo);
                        if (result == 1)
                        {
                            MessageBox.Show("保存成功");
                            DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            MessageBox.Show("保存失败");
                            DialogResult = DialogResult.No;
                        }

                    }
                    else
                    {
                        //装饰线条
                        //1、先验证是否填写必填项
                        if (!ValidateZsxtData(dlo)) return;
                        //2、处理数据
                        dlo = HandleZsxtOrder(dlo);
                        //保存数据
                        int result = dal.UpdateDetailOrder(dlo);
                        if (result == 1)
                        {
                            MessageBox.Show("保存成功");
                            DialogResult = DialogResult.OK;
                        }
                        else
                        {
                            MessageBox.Show("保存失败");
                            DialogResult = DialogResult.No;
                        }
                    }
                }
                
            }
        }
        //取消
        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.No;
        }

        //类别选择事件
        private void cbType_SelectionChangeCommitted(object sender, EventArgs e)
        {
            if (this.cbType.SelectedIndex >= 0)
            {
                if (this.cbType.SelectedValue.ToString().Equals("0"))//选择门型编号变更控件使用装填
                {
                    SetControlState(true);
                    SetLabelState(true);
                    this.label9.Text = "边框颜色：";

                }
                else
                { //选择装饰线条变更控件使用装填
                    SetControlState(false);
                    SetLabelState(false);
                    this.cbpackage.SelectedIndex = 0;
                    this.label9.Text = "表面PVC颜色：";
                    //this.lbz3.Visible = true;
                }
            }
        }


        //门型编号选择事件
        private void cbMxbh_SelectionChangeCommitted(object sender, EventArgs e)
        {
            //int index = this.cbMxbh.SelectedIndex;
           // string SS = this.cbMxbh.SelectedValue.ToString();
            if (this.cbMxbh.SelectedIndex >= 0)
            {
                string mxbh = this.cbMxbh.SelectedValue.ToString();
                mxbh = mxbh.ToUpper();
                //MessageBox.Show(mxbh);
                DataRow[] drs = dtMxbh.Select("mxbh='" + mxbh + "'");
                if (drs.Length == 0)
                {
                    this.tbKxbh.Text = "";
                    this.tbXbmc.Text = "";
                    this.gbGlass.Enabled = false;
                    this.cbGlassType.Enabled = false;
                    return;
                }
                else if (drs.Length == 1)
                {
                    this.tbKxbh.Text = drs[0]["kxbh"].ToString();
                    this.tbXbmc.Text = drs[0]["xbmc"].ToString();
                    this.tbMenxingprice.Text = drs[0]["price"].ToString();
                    this.tbSpecial.Text = drs[0]["specialname"].ToString();
                    this.tbAddPrice.Text = drs[0]["addprice"].ToString();
                    this.tbIsSoft.Text = drs[0]["issoft"].ToString();
                    this.tbIsSpecial.Text = drs[0]["special"].ToString();
                    this.tbglass.Text = drs[0]["glass"].ToString();
                    if (drs[0]["glass"].ToString().Equals("0"))
                    {
                        this.cbGlassType.SelectedIndex = 0;
                        foreach (RadioButton rb in this.gbGlass.Controls)
                        {
                            if (rb.Tag.ToString() == "0")
                            {
                                rb.Checked = true;
                            }
                            else
                            {
                                rb.Checked = false;
                            }
                        }
                        this.gbGlass.Enabled = false;
                        this.cbGlassType.Enabled = false;
                    }
                    else
                    {
                        this.cbGlassType.SelectedIndex = 1;
                        foreach (RadioButton rb in this.gbGlass.Controls)
                        {
                            if (rb.Tag.ToString() == "0")
                            {
                                rb.Checked = true;
                            }
                            else
                            {
                                rb.Checked = false;
                            }
                        }
                        this.gbGlass.Enabled = true;
                        this.cbGlassType.Enabled = true;
                    }

                    DataTable dt = dal.GetExpression(drs[0]["kxbh"].ToString());
                    if (dt != null)
                    {
                        this.lbcare.Text = dt.Rows[0]["remarks"].ToString();
                    }
                    else {
                        this.lbcare.Text = "";
                    }
                    if ("PB-PB01".Equals(mxbh))
                    {
                        this.lbxbcolor.Visible = false;
                        this.lbxbbq.Visible = false;
                        this.tbxbcolor.Visible = false;
                        
                    }
                    else {
                        this.lbxbcolor.Visible = true;
                        this.lbxbbq.Visible = true;
                        this.tbxbcolor.Visible = true;
                        
                    }
                    //根据门型获取另加装饰选项
                    DataTable dectable = dicType.GetOtherName(drs[0]["kxbh"].ToString());
                    if (dectable == null || dectable.Rows.Count <= 0)
                    {
                        this.lbOtherRed.Visible = false;
                        this.lbOther.Visible = false;
                        this.lbOther.Text = "";
                        this.cbOther.Visible = false;
                        this.cbOther.DataSource = null;
                    }
                    else
                    {
                        object o = dectable.Rows[0]["decname"];
                        if (o == DBNull.Value || o == null)
                        {
                            this.lbOtherRed.Visible = false;
                            this.lbOther.Visible = false;
                            this.lbOther.Text = "";
                            this.cbOther.Visible = false;
                            this.cbOther.DataSource = null;
                        }
                        else
                        {
                            this.lbOtherRed.Visible = true;
                            this.lbOther.Visible = true;
                            this.lbOther.Text = o + ":";
                            this.cbOther.Visible = true;
                            otherDetail = dicType.GetOtherDetail(drs[0]["kxbh"].ToString(), dectable.Rows[0]["oid"].ToString());
                            otherDetail.Rows.InsertAt( otherDetail.NewRow(),0);
                            this.cbOther.DataSource = otherDetail;
                        }
                    }
                }
                else
                {
                    MessageBox.Show("出现重复值");
                    return;
                }
            }
        }
        //是否特殊玻璃
        private void rbGlassYes_CheckedChanged(object sender, EventArgs e)
        {
            if (this.rbGlassYes.Checked)
            {
                this.cbGlassType.Enabled = true;

            }
            else
            {
                this.cbGlassType.Enabled = true;
                this.cbGlassType.SelectedIndex = 1;
            }
        }
        //是否芯板做旧
        private void rbXbzjYes_CheckedChanged(object sender, EventArgs e)
        {
            if (rbXbzjYes.Checked)
            {
                this.cbXbzjColor.DataSource = dtXbzjColor;
                this.cbXbzjColor.DisplayMember = "mcolor";
                this.cbXbzjColor.ValueMember = "mid";
                this.cbXbzjColor.Enabled = true;
                lbzj.Visible = true;
                
            }
            else
            {
                this.cbXbzjColor.SelectedIndex = 0;
                this.cbXbzjColor.Enabled = false;
                lbzj.Visible = false;
            }
        }
       

        #endregion 按钮事件



        #region 自定义方法
        

        //处理门型订单数据
        public DetailOrder HandleMxOrder(DetailOrder dlo){

            //1、根据门型公式对门型分门别类计算芯板和物料使用量
            DataTable dtExpression = dal.GetExpression(dlo.Kxbh);
            if (dtExpression.Rows.Count == 1)
            {
                MSScriptControl.ScriptControl ms = new MSScriptControl.ScriptControl();
                ms.Language = "JavaScript";
                DataRow dr = dtExpression.Rows[0];
                string kuan = dlo.Kuan;
                string gao = dlo.Gao;
                string num = dlo.Num;
                if (dr["ispb"].ToString().Equals("0"))//非平板门计算芯板
                {
                    if (dlo.IsZh == 0)
                    {
                        if (Convert.ToDecimal(dlo.Gao) > Convert.ToDecimal(dr["gao"]) && Convert.ToDecimal(dlo.Kuan) > Convert.ToDecimal(dr["kuan"]))
                        {
                            string xbwidth = dr["nozhwidth"].ToString();
                            string xbheight = dr["nozhheight"].ToString();
                            string xbyl = dr["nozhxbyl"].ToString();
                            xbwidth = xbwidth.Replace("kuan",dlo.Kuan);
                            xbheight = xbheight.Replace("gao", dlo.Gao);
                            dlo.Xbwidth = Math.Round(Convert.ToDecimal(ms.Eval(xbwidth))).ToString();
                            dlo.Xbheight = Math.Round(Convert.ToDecimal(ms.Eval(xbheight))).ToString();
                            xbyl = xbyl.Replace("xbwidth", dlo.Xbwidth).Replace("xbheight", dlo.Xbheight).Replace("num", dlo.Num);
                            dlo.xbyl=Math.Round(Convert.ToDecimal(ms.Eval(xbyl)),3).ToString();
                            //dlo.Xbwidth = Math.Round((Convert.ToDecimal(dlo.Kuan) - 80 * 2 + 12), 3).ToString();
                            //dlo.Xbheight = Math.Round(((Convert.ToDecimal(dlo.Gao) - 80 * 2 + 12)), 3).ToString();
                            ////dlo.Wlsl = Math.Round((Convert.ToDecimal(dlo.Kuan) + Convert.ToDecimal(dlo.Gao)) * 2 * Convert.ToInt32(dlo.Num) / 1000, 3).ToString();//物料计算
                            //dlo.xbyl = Math.Round(Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.Xbheight) * Convert.ToInt32(dlo.Num) / 1000000, 3).ToString();
                        }
                    }
                    else if (dlo.IsZh == 1)
                    {
                        if (Convert.ToDecimal(dlo.Gao) > Convert.ToDecimal(dr["gao"]) && Convert.ToDecimal(dlo.Kuan) > Convert.ToDecimal(dr["kuan"]))
                        {
                            string xbwidth = dr["defaultwidth"].ToString();
                            string xbtopheight = dr["defaulttopheight"].ToString();
                            string xbdownheight = dr["defaultdownheight"].ToString();
                            string xbyl = dr["defaultxbyl"].ToString();
                            xbwidth = xbwidth.Replace("kuan",dlo.Kuan);
                            xbtopheight = xbtopheight.Replace("gao",dlo.Gao);
                            xbdownheight = xbdownheight.Replace("gao", dlo.Gao);
                            dlo.Xbwidth = Math.Round(Convert.ToDecimal(ms.Eval(xbwidth))).ToString();
                            dlo.XbTopHeight = Math.Round(Convert.ToDecimal(ms.Eval(xbtopheight))).ToString();
                            dlo.xbDownHeight = Math.Round(Convert.ToDecimal(ms.Eval(xbdownheight))).ToString();
                            xbyl = xbyl.Replace("xbwidth", dlo.Xbwidth).Replace("xbtopheight", dlo.XbTopHeight).Replace("xbdownheight", dlo.xbDownHeight).Replace("num", dlo.Num);
                            dlo.xbyl = Math.Round(Convert.ToDecimal(ms.Eval(xbyl)), 3).ToString();
                            //dlo.xbDownHeight = Math.Round(((Convert.ToDecimal(dlo.Gao) - 80 * 3) / 10 * 4 + 12), 3).ToString();
                            //dlo.XbTopHeight = Math.Round(((Convert.ToDecimal(dlo.Gao) - 80 * 3) / 10 * 6 + 12), 3).ToString();
                            //dlo.Xbwidth = Math.Round((Convert.ToDecimal(dlo.Kuan) - 80 * 2 + 12), 3).ToString();
                            ////dlo.Wlsl = Math.Round((Convert.ToDecimal(dlo.Kuan) + Convert.ToDecimal(dlo.Gao)) * 2 * Convert.ToInt32(dlo.Num) / 1000, 3).ToString();//物料计算
                            //dlo.xbyl = Math.Round((Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.XbTopHeight) * Convert.ToInt32(dlo.Num) + Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.xbDownHeight) * Convert.ToInt32(dlo.Num)) / 1000000, 3).ToString();
                        }
                    }
                    else if (dlo.IsZh == 2)
                    {
                        if (Convert.ToDecimal(dlo.Gao) > Convert.ToDecimal(dr["gao"]) && Convert.ToDecimal(dlo.Kuan) > Convert.ToDecimal(dr["kuan"]))
                        {
                            string xbwidth = dr["definewidth"].ToString();
                            string xbdownheight = dr["definedownheight"].ToString();
                            string xbtopheight = dr["definetopheight"].ToString();
                            xbwidth = xbwidth.Replace("kuan",dlo.Kuan);
                            xbdownheight = xbdownheight.Replace("gao", dlo.Gao).Replace("xbtopheight",dlo.XbTop);
                            xbtopheight=xbtopheight.Replace("xbtopheight",dlo.XbTop);
                            dlo.Xbwidth = Math.Round(Convert.ToDecimal(ms.Eval(xbwidth))).ToString();
                            dlo.xbDownHeight = Math.Round(Convert.ToDecimal(ms.Eval(xbdownheight))).ToString();
                            dlo.XbTopHeight = Math.Round(Convert.ToDecimal(ms.Eval(xbtopheight))).ToString();
                            string xbyl = dr["definexbyl"].ToString();
                            xbyl = xbyl.Replace("xbwidth", dlo.Xbwidth).Replace("xbtopheight", dlo.XbTopHeight).Replace("xbdownheight", dlo.xbDownHeight).Replace("num", dlo.Num);
                            dlo.xbyl = Math.Round(Convert.ToDecimal(ms.Eval(xbyl)), 3).ToString();
                            //dlo.Xbwidth = Math.Round((Convert.ToDecimal(dlo.Kuan) - 80 * 2 + 12), 3).ToString();
                            //dlo.xbyl = Math.Round((Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.XbTopHeight) * Convert.ToInt32(dlo.Num) + Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.xbDownHeight) * Convert.ToInt32(dlo.Num)) / 1000000, 3).ToString();
                        }
                    }
                    else
                    {
                        throw new Exception("中横值出现问题");
                    }
                }
                else if (dr["ispb"].ToString().Equals("1"))
                { 
                    //平板门 不计算芯板
                    string xbwidth = dr["nozhwidth"].ToString();
                    string xbheight = dr["nozhheight"].ToString();
                    xbwidth = xbwidth.Replace("kuan",dlo.Kuan);
                    xbheight = xbheight.Replace("gao", dlo.Gao);
                    dlo.Xbwidth = xbwidth;
                    dlo.Xbheight = xbheight;

                    string xbyl = dr["nozhxbyl"].ToString();
                    xbyl = xbyl.Replace("xbwidth", dlo.Xbwidth).Replace("xbheight", dlo.Xbheight).Replace("num", dlo.Num);
                    dlo.xbyl = Math.Round(Convert.ToDecimal(ms.Eval(xbyl)), 3).ToString();
                    
                    //dlo.Xbwidth = dlo.Kuan;
                    //dlo.Xbheight = dlo.Gao;
                    //dlo.xbyl = Math.Round(Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.Xbheight) * Convert.ToInt32(dlo.Num) / 1000000, 3).ToString();
                }
                string wlsl = dr["wlsl"].ToString();
                wlsl = wlsl.Replace("kuan", dlo.Kuan).Replace("gao", dlo.Gao).Replace("num",dlo.Num);
                dlo.Wlsl = Math.Round(Convert.ToDecimal(ms.Eval(wlsl)),3).ToString();//框型用量
            }
            else {
                MessageBox.Show("获取公式失败，请重新计算");
                throw new Exception("存在重复公式");
            }

            #region 已更新升级流程
            /**
            if (!string.IsNullOrWhiteSpace(dlo.Kxbh) && dlo.Kxbh.Equals("P60H"))
            {

                if (dlo.IsZh == 0)
                {
                    if (Convert.ToDecimal(dlo.Gao) > 60 * 2 && Convert.ToDecimal(dlo.Kuan) > 60 * 2)
                    {
                        dlo.Xbwidth = Math.Round((Convert.ToDecimal(dlo.Kuan) - 60 * 2 + 15), 3).ToString();
                        dlo.Xbheight = Math.Round(((Convert.ToDecimal(dlo.Gao) - 60 * 2 + 15)), 3).ToString();
                        dlo.xbyl = Math.Round(Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.Xbheight) * Convert.ToInt32(dlo.Num) / 1000000, 3).ToString();
                    } 
                }
                else if (dlo.IsZh == 1)
                {
                    if (Convert.ToDecimal(dlo.Gao) > 60 * 3&&Convert.ToDecimal(dlo.Kuan)> 60 * 2)
                    {
                        dlo.xbDownHeight = Math.Round(((Convert.ToDecimal(dlo.Gao) - 60 * 3) / 10 * 4 + 15), 3).ToString();
                        dlo.XbTopHeight = Math.Round(((Convert.ToDecimal(dlo.Gao) - 60 * 3) / 10 * 6 + 15), 3).ToString();
                        dlo.Xbwidth = Math.Round((Convert.ToDecimal(dlo.Kuan) - 60 * 2 + 15), 3).ToString();
                        dlo.xbyl = Math.Round((Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.XbTopHeight) * Convert.ToInt32(dlo.Num) + Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.xbDownHeight) * Convert.ToInt32(dlo.Num)) / 1000000, 3).ToString();
                    }
                }else if(dlo.IsZh==2){
                    if (Convert.ToDecimal(dlo.Gao) > 60 * 3 && Convert.ToDecimal(dlo.Kuan) > 60 * 2)
                    {
                        dlo.Xbwidth = Math.Round((Convert.ToDecimal(dlo.Kuan) - 60 * 2 + 15), 3).ToString();
                        dlo.xbyl = Math.Round((Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.XbTopHeight) * Convert.ToInt32(dlo.Num) + Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.xbDownHeight) * Convert.ToInt32(dlo.Num)) / 1000000, 3).ToString();
                    }
                }
                else {
                    throw new Exception("中横值出现问题");
                }
            }
            else if (!string.IsNullOrWhiteSpace(dlo.Kxbh) && dlo.Kxbh.Equals("P75072"))
            {
                if (dlo.IsZh == 0)
                {
                    if (Convert.ToDecimal(dlo.Gao) > 75 * 2&&Convert.ToDecimal(dlo.Kuan) > 75 * 2)
                    {
                        dlo.Xbwidth = Math.Round((Convert.ToDecimal(dlo.Kuan) - 75 * 2 + 15), 3).ToString();
                        dlo.Xbheight = Math.Round(((Convert.ToDecimal(dlo.Gao) - 75 * 2 + 15)), 3).ToString();
                       // dlo.Wlsl = Math.Round((Convert.ToDecimal(dlo.Kuan) + Convert.ToDecimal(dlo.Gao)) * 2 * Convert.ToInt32(dlo.Num) / 1000, 3).ToString();//物料计算
                        dlo.xbyl = Math.Round(Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.Xbheight) * Convert.ToInt32(dlo.Num) / 1000000, 3).ToString();
                    }
                }
                else if (dlo.IsZh == 1)
                {
                    if (Convert.ToDecimal(dlo.Gao) > 75 * 3 && Convert.ToDecimal(dlo.Kuan) > 75 * 2)
                    {
                        dlo.xbDownHeight = Math.Round(((Convert.ToDecimal(dlo.Gao) - 75 * 3) / 10 * 4 + 15), 3).ToString();
                        dlo.XbTopHeight = Math.Round(((Convert.ToDecimal(dlo.Gao) - 75 * 3) / 10 * 6 + 15), 3).ToString();
                        dlo.Xbwidth = Math.Round((Convert.ToDecimal(dlo.Kuan) - 75 * 2 + 15), 3).ToString();
                        //dlo.Wlsl = Math.Round((Convert.ToDecimal(dlo.Kuan) + Convert.ToDecimal(dlo.Gao)) * 2 * Convert.ToInt32(dlo.Num) / 1000, 3).ToString();//物料计算
                        dlo.xbyl = Math.Round((Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.XbTopHeight) * Convert.ToInt32(dlo.Num) + Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.xbDownHeight) * Convert.ToInt32(dlo.Num)) / 1000000, 3).ToString();

                    }
                }
                else if (dlo.IsZh == 2) {
                    if (Convert.ToDecimal(dlo.Gao) > 75 * 3 && Convert.ToDecimal(dlo.Kuan) > 75 * 2)
                    {
                        //dlo.xbDownHeight = Math.Round(((Convert.ToDecimal(dlo.Gao) - 75 * 3) / 10 * 4 + 15), 3).ToString();
                        //dlo.XbTopHeight = Math.Round(((Convert.ToDecimal(dlo.Gao) - 75 * 3) / 10 * 6 + 15), 3).ToString();
                        dlo.Xbwidth = Math.Round((Convert.ToDecimal(dlo.Kuan) - 75 * 2 + 15), 3).ToString();
                        //dlo.Wlsl = Math.Round((Convert.ToDecimal(dlo.Kuan) + Convert.ToDecimal(dlo.Gao)) * 2 * Convert.ToInt32(dlo.Num) / 1000, 3).ToString();//物料计算
                        dlo.xbyl = Math.Round((Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.XbTopHeight) * Convert.ToInt32(dlo.Num) + Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.xbDownHeight) * Convert.ToInt32(dlo.Num)) / 1000000, 3).ToString();

                    }
                }
                else
                {
                    throw new Exception("中横值出现问题");
                }
            }
            else if (!string.IsNullOrWhiteSpace(dlo.Kxbh) && dlo.Kxbh.Equals("P80071")) 
            {
                if (dlo.IsZh == 0)
                {
                    if (Convert.ToDecimal(dlo.Gao) > 80 * 2 && Convert.ToDecimal(dlo.Kuan) > 80 * 2)
                    {
                        dlo.Xbwidth = Math.Round((Convert.ToDecimal(dlo.Kuan) - 80 * 2 + 12), 3).ToString();
                        dlo.Xbheight = Math.Round(((Convert.ToDecimal(dlo.Gao) - 80 * 2 + 12)), 3).ToString();
                        //dlo.Wlsl = Math.Round((Convert.ToDecimal(dlo.Kuan) + Convert.ToDecimal(dlo.Gao)) * 2 * Convert.ToInt32(dlo.Num) / 1000, 3).ToString();//物料计算
                        dlo.xbyl = Math.Round(Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.Xbheight) * Convert.ToInt32(dlo.Num) / 1000000, 3).ToString();
                    }
                }
                else if (dlo.IsZh == 1)
                {
                    if (Convert.ToDecimal(dlo.Gao) > 80 * 3 && Convert.ToDecimal(dlo.Kuan) > 80 * 2)
                    {
                        dlo.xbDownHeight = Math.Round(((Convert.ToDecimal(dlo.Gao) - 80 * 3) / 10 * 4 + 12), 3).ToString();
                        dlo.XbTopHeight = Math.Round(((Convert.ToDecimal(dlo.Gao) - 80 * 3) / 10 * 6 + 12), 3).ToString();
                        dlo.Xbwidth = Math.Round((Convert.ToDecimal(dlo.Kuan) - 80 * 2 + 12), 3).ToString();
                        //dlo.Wlsl = Math.Round((Convert.ToDecimal(dlo.Kuan) + Convert.ToDecimal(dlo.Gao)) * 2 * Convert.ToInt32(dlo.Num) / 1000, 3).ToString();//物料计算
                        dlo.xbyl = Math.Round((Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.XbTopHeight) * Convert.ToInt32(dlo.Num) + Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.xbDownHeight) * Convert.ToInt32(dlo.Num)) / 1000000, 3).ToString();
                    }
                }
                else if (dlo.IsZh == 2) {
                    if (Convert.ToDecimal(dlo.Gao) > 80 * 3 && Convert.ToDecimal(dlo.Kuan) > 80 * 2)
                    {
                        //dlo.xbDownHeight = Math.Round(((Convert.ToDecimal(dlo.Gao) - 80 * 3) / 10 * 4 + 12), 3).ToString();
                        //dlo.XbTopHeight = Math.Round(((Convert.ToDecimal(dlo.Gao) - 80 * 3) / 10 * 6 + 12), 3).ToString();
                        dlo.Xbwidth = Math.Round((Convert.ToDecimal(dlo.Kuan) - 80 * 2 + 12), 3).ToString();
                        //dlo.Wlsl = Math.Round((Convert.ToDecimal(dlo.Kuan) + Convert.ToDecimal(dlo.Gao)) * 2 * Convert.ToInt32(dlo.Num) / 1000, 3).ToString();//物料计算
                        dlo.xbyl = Math.Round((Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.XbTopHeight) * Convert.ToInt32(dlo.Num) + Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.xbDownHeight) * Convert.ToInt32(dlo.Num)) / 1000000, 3).ToString();
                    }
                }
                else
                {
                    throw new Exception("中横值出现问题");
                }
            }
            else if (!string.IsNullOrWhiteSpace(dlo.Kxbh) && dlo.Kxbh.Equals("PB")) {
                dlo.Xbwidth = dlo.Kuan;
                dlo.Xbheight = dlo.Gao;
                dlo.xbyl = Math.Round(Convert.ToDecimal(dlo.Xbwidth) * Convert.ToDecimal(dlo.Xbheight) * Convert.ToInt32(dlo.Num) / 1000000, 3).ToString();
            }
            **/
            #endregion  更新流程

            //dlo.Wlsl = Math.Round((Convert.ToDecimal(dlo.Kuan) + Convert.ToDecimal(dlo.Gao)) * 2 * Convert.ToInt32(dlo.Num) / 1000, 3).ToString();//物料计算
            //2、计算面积  
            decimal mj = Convert.ToDecimal(dlo.Gao)/1000*Convert.ToDecimal(dlo.Kuan)/1000;
            if (mj.CompareTo(Convert.ToDecimal(0.1)) < 0)
            {
                mj = Convert.ToDecimal(0.1);
            }
            mj = Math.Round(mj * Convert.ToDecimal(dlo.Num),3);//单个面积*数量

            dlo.PackageTotal = Math.Round(mj*Convert.ToDecimal(dlo.PackagePrice),3).ToString();//新增计算包装价格

            dlo.Mianji = mj.ToString();
            //3、计算价格（不含特殊工艺价格）
            dlo.Total = (mj * Convert.ToDecimal(dlo.Price)).ToString();
            //4、计算特殊玻璃价格（特殊工艺）
            if (dlo.IsGlass == 1)
            {
                DataRow[] drGlass = dtGlassType.Select("gid='"+dlo.GlassId+"'");//测试
                if (drGlass.Length == 1)
                {
                    decimal glassDj =Convert.ToDecimal(drGlass[0]["glassPrice"]);
                    dlo.GlassPrice = (mj * glassDj).ToString();
                }
                else {
                    dlo.GlassPrice="0";
                    MessageBox.Show("特殊玻璃类别没有找到");
                }
            } 
            else 
            {
                dlo.GlassPrice = "0";
            }
            //5、计算芯板做旧颜色价格（特殊工艺）
            if(dlo.IsOld==1){
                DataRow[] drColor = dtXbzjColor.Select("mid='"+dlo.OldColorId+"'");
                if (drColor.Length == 1) {
                    decimal colorDj = Convert.ToDecimal(drColor[0]["mprice"]);
                    dlo.OldPrice = (colorDj * mj).ToString();
                }
            }
            //6、计算门型按扇附加费
            if (dlo.IsSpecial == 1) {
                dlo.SpecialTotal = Math.Round(Convert.ToDecimal(dlo.SpecialPrice) * Convert.ToInt32(dlo.Num),3);
            }
            return dlo;
        }

        //处理装饰线条数据
        public DetailOrder HandleZsxtOrder(DetailOrder dlo) {
            //根据类别计算价格
            DataRow[] drZsxt = dtZsxt.Select("zsbh='"+dlo.Mxbh+"'");
            if (drZsxt.Length == 1)
            {
                decimal zscd = 0;
                //1、计算正常总价
                dlo.Price = drZsxt[0]["zsdj"].ToString();
                if (drZsxt[0]["zslb"].ToString().Equals("1"))
                {
                    dlo.Total = Math.Round(Convert.ToDecimal(dlo.Num) * Convert.ToDecimal(dlo.Price), 3).ToString();
                    //2、计算做旧总价
                    if (dlo.IsOld == 1) {//类别为1  的是 柱头 是按个计算
                        zscd = Convert.ToDecimal(dlo.Num) * Convert.ToDecimal(dlo.Gao) / 1000;
                        DataRow[] drs = dtZsxtZj.Select("mid='" + dlo.OldColorId + "'");
                        if (drs.Length == 1)
                        {
                            decimal zjdj = Convert.ToDecimal(drs[0]["mprice"]);
                            dlo.OldPrice = Math.Round(zscd * zjdj, 3).ToString();
                        }
                        else
                        {
                            throw new Exception("做旧单价没找到");
                        }
                        //dlo.OldPrice = Math.Round(Convert.ToDecimal(dlo.Num) * Convert.ToDecimal(drZsxt[0]["oldprice"]), 3).ToString();
                    }
                }
                else {
                    //zscd = Convert.ToDecimal(dlo.Num) * Convert.ToDecimal(dlo.Price) * Convert.ToDecimal(dlo.Gao) / 1000;
                    zscd = Convert.ToDecimal(dlo.Num)  * Convert.ToDecimal(dlo.Gao) / 1000;
                    decimal zsPrice = zscd * Convert.ToDecimal(dlo.Price);
                    dlo.Total = Math.Round(zsPrice, 3).ToString();
                    //2、计算做旧总价
                    if (dlo.IsOld == 1) { //类别为0  是其他 按米算
                        DataRow[] drs = dtZsxtZj.Select("mid='"+dlo.OldColorId+"'");
                        if(drs.Length==1){
                            decimal zjdj= Convert.ToDecimal(drs[0]["mprice"]);
                            dlo.OldPrice = Math.Round(zscd * zjdj,3).ToString();
                        }else{
                            throw new Exception("做旧单价没找到");
                        }
                    }
                }
           }
            else {
                throw new Exception("装饰条没有找到对应单价");
            }
            return dlo;
        }
        //根据门型还是装饰线条选择必填选状态显示
        public void SetLabelState(bool flag){
            this.lbm1.Visible = flag;
            this.lbm2.Visible = flag;
            this.lbm3.Visible = flag;
            this.lbm4.Visible = flag;
            this.lbm5.Visible = flag;
            this.lbm6.Visible = flag;
            this.lbxbcolor.Visible = flag;
            this.lbpackage.Visible = flag;//后期增加包装类别

            this.lbz1.Visible = !flag;
            this.lbz2.Visible = !flag;
            if (rbXbzjYes.Checked || rbOldYes.Checked) {
                this.lbzj.Visible = true;
            }
            if (rbGlassYes.Checked) {
                lbglassmust.Visible = true;
            }
            if (rbZhDefined.Checked) {
                lbtopmust.Visible = true;
            }
            
        }


        //根据选择门型还是装饰线条控制控件状态
        public void SetControlState(bool flag) {
            this.cbMxbh.Enabled = flag;
            this.tbKxbh.Enabled = flag;
            this.tbXbmc.Enabled = flag;
            this.tbMenxingprice.Enabled = flag;
            this.tbIsSpecial.Enabled = flag;
            this.tbSpecial.Enabled = flag;
            this.tbXtprice.Enabled = !flag;
            this.tbGao.Enabled = flag;
            //this.tbHou.Enabled = flag;
            this.tbKuan.Enabled = flag;

            this.cbWenlu.Enabled = flag;

            this.cbPjfs.Enabled = flag;
            //this.gbGlass.Enabled = false;//在没有选择前默认是不可选
            if (this.rbGlassYes.Checked)
            {
                //this.gbGlass.Enabled = true;
                this.cbGlassType.Enabled = true;
            }
            else {
               // this.gbGlass.Enabled = false;
                this.cbGlassType.Enabled = false;
            }
           // this.cbGlassType.Enabled = false;

            //this.tbXbxs.Enabled = flag;
            this.cbColor.Enabled = true;
            this.tbNum.Enabled = true;

            this.gbXbzj.Enabled = flag;
            if (this.rbXbzjYes.Checked)
            {
                this.cbXbzjColor.Enabled = true;
            }
            else {
                this.cbXbzjColor.Enabled = false;
            }
            

            this.gbZh.Enabled = flag;
            this.cbDirection.Enabled = flag;
            if (this.rbZhDefined.Checked)
            {
                this.tbTopHeight.Enabled = true;
                //this.tbDownHeight.Enabled = true;
            }
            else
            {
                this.tbTopHeight.Enabled = false;
               // this.tbDownHeight.Enabled = false;
            }
            this.cbZsxt.Enabled = !flag;
            this.tbCd.Enabled = !flag;
            this.gbIsold.Enabled = !flag;

            this.tbOtherDesc.Enabled = true;
            this.tbOtherPrice.Enabled = true;
            this.tbBzbz.Enabled = true;
            //后期增加包装类型
            this.cbpackage.Enabled = flag;
            this.tbpackageprice.Enabled = flag;

            this.tbxbcolor.Enabled = flag;



        }

        //加载预置字典
        private void LoadData() {

            //类别赋值】
            //dic.Add(-1,"");
            dic.Add(0, "门型");
            dic.Add(1, "装饰线条");
            BindingSource bs = new BindingSource();
            bs.DataSource = dic;
            this.cbType.DataSource = bs;
            this.cbType.DisplayMember = "value";
            this.cbType.ValueMember = "key";
            //门型赋值\
            dtMxbh = dicType.MxbhListAll();
            DataRow drmxbh = dtMxbh.NewRow();
            dtMxbh.Rows.InsertAt(drmxbh,0);
            this.cbMxbh.DataSource = dtMxbh;
            this.cbMxbh.ValueMember = "mxbh";
            this.cbMxbh.DisplayMember = "mxsm";
            //拼接方式赋值
            this.cbPjfs.DataSource = dicType.PjfsListAll();
            this.cbPjfs.DisplayMember = "pjfs";
            this.cbPjfs.ValueMember = "pid";
            //玻璃种类
            //dtGlassType=dicType.SpecialGlassListAll();
            //DataRow drGlassType = dtGlassType.NewRow();
            //dtGlassType.Rows.InsertAt(drGlassType,0);
            //this.cbGlassType.DataSource = dtGlassType;
            //this.cbGlassType.DisplayMember = "glasstype";
            //this.cbGlassType.ValueMember = "gid";
            dtGlassType = dicType.NormalGlassListAll();
            DataRow drGlassType = dtGlassType.NewRow();
            dtGlassType.Rows.InsertAt(drGlassType,0);
            this.cbGlassType.DataSource = dtGlassType;
            this.cbGlassType.DisplayMember = "glasstype";
            this.cbGlassType.ValueMember = "gid";
            //表面pvc颜色
            DataTable dtColor = dicType.MenxingColorListAll();
            DataRow drColor = dtColor.NewRow();
            dtColor.Rows.InsertAt(drColor,0);
            this.cbColor.DataSource = dtColor;
            this.cbColor.DisplayMember = "mcolor";
            this.cbColor.ValueMember = "mid";

            //芯板做旧颜色
            dtXbzjColor = dicType.MenxingXbzjColorListAll();
            DataRow drXbzjColor = dtXbzjColor.NewRow();
            dtXbzjColor.Rows.InsertAt(drXbzjColor, 0);

            //打孔方向
            DataTable dtDirection = dicType.KkfxListAll();
            DataRow drDirection = dtDirection.NewRow();
            dtDirection.Rows.InsertAt(drDirection,0);
            this.cbDirection.DataSource = dtDirection;
            this.cbDirection.DisplayMember = "direction";
            this.cbDirection.ValueMember = "kid";
            //装饰线条
             dtZsxt = dicType.ZsxtListAll();
           DataRow drZsxt = dtZsxt.NewRow();
            dtZsxt.Rows.InsertAt(drZsxt,0);
            this.cbZsxt.DataSource = dtZsxt;
            this.cbZsxt.DisplayMember = "zsmc";
            this.cbZsxt.ValueMember = "zsbh";

            //装饰线条做旧
            dtZsxtZj = dicType.ZsxtzjColorListAll();
            DataRow drXtzjColor = dtZsxtZj.NewRow();
            dtZsxtZj.Rows.InsertAt(drXtzjColor, 0);

            //包装类型 后期增加
            dtPackage = dicType.GetPackageType();
            DataRow drPackage = dtPackage.NewRow();
            dtPackage.Rows.InsertAt(drPackage,0);
            this.cbpackage.DataSource = dtPackage;
            this.cbpackage.DisplayMember = "ptype";
            this.cbpackage.ValueMember="pid";
            //另加装饰
            this.cbOther.DisplayMember = "decname";
            this.cbOther.ValueMember = "oid";
            this.cbOther.DataSource = null;
            
        }

        //门型必填项检查
        private bool ValidateMxData(DetailOrder dlo)
        {
            bool flag = true;
            DataTable dt = new DataTable();
            DataRow[] drs = null;
            if (string.IsNullOrWhiteSpace(dlo.Danhao))
            {
                MessageBox.Show("单号不能为空");
                flag = false;
                return flag;
            }
            if (string.IsNullOrWhiteSpace(dlo.Mxbh))
            {
                MessageBox.Show("门型编号不能为空");
                flag = false;
                return flag;
            }
            else {
                drs = dtMxbh.Select("mxbh='" + dlo.Mxbh + "' and limitcc = '1'");
            }
            if (string.IsNullOrWhiteSpace(dlo.Kxbh))
            {
                MessageBox.Show("框型编号不能为空");
                flag = false;
                return flag;
            }
            else 
            {
                dt = dal.GetExpression(dlo.Kxbh);
            }
            if (string.IsNullOrWhiteSpace(dlo.Xbmc))
            {
                MessageBox.Show("芯板名称不能为空");
                flag = false;
                return flag;
            }
            if (string.IsNullOrWhiteSpace(dlo.Pjfs))
            {
                MessageBox.Show("拼接方式不能为空");
                flag = false;
                return flag;
            }
            if (dlo.IsGlass == 1) {
                if (string.IsNullOrWhiteSpace(dlo.GlassType))
                {
                    MessageBox.Show("玻璃类别不能为空");
                    flag = false;
                    return flag;
                }
            }

            if (string.IsNullOrWhiteSpace(dlo.Gao))
            {
                MessageBox.Show("高不能为空");
                flag = false;
                return flag;
            }
            else 
            {
                if (dt.Rows.Count > 0)
                {
                    if (Convert.ToDecimal(dlo.Gao) < Convert.ToDecimal(dt.Rows[0]["gao"]))
                    {
                        flag = false;
                        MessageBox.Show("门板高度不能低于" + dt.Rows[0]["gao"] + "mm");
                        return flag;
                    }
                }
                if (drs != null && drs.Count() > 0) {
                    if (Convert.ToDecimal(dlo.Gao) < Convert.ToDecimal(drs[0]["limitgao"]))
                    {
                        flag = false;
                        MessageBox.Show("门板高度低于" + drs[0]["limitgao"] + "mm,不可做" + drs[0]["mxsm"].ToString() + "门型");
                        return flag;
                    }
                }
                
            }
            //删除
            //if (string.IsNullOrWhiteSpace(dlo.Hou))
            //{
            //    MessageBox.Show("厚不能为空");
            //    flag = false;
            //    return flag;
            //}
            if (string.IsNullOrWhiteSpace(dlo.Kuan))
            {
                MessageBox.Show("宽不能为空");
                flag = false;
                return flag;
            }
            else 
            {
                if (dt.Rows.Count > 0)
                {
                    if (Convert.ToDecimal(dlo.Kuan) < Convert.ToDecimal(dt.Rows[0]["kuan"]))
                    {
                        flag = false;
                        MessageBox.Show("门板宽度不能低于" + dt.Rows[0]["kuan"] + "mm");
                        return flag;
                    }
                }
                if (drs != null && drs.Count() > 0)
                {
                    if (Convert.ToDecimal(dlo.Kuan) < Convert.ToDecimal(drs[0]["limitkuan"]))
                    {
                        flag = false;
                        MessageBox.Show("门板宽度低于" + drs[0]["limitkuan"] + "mm,不可做" + drs[0]["mxsm"].ToString() + "门型");
                        return flag;
                    }
                }
            }
            //if (string.IsNullOrWhiteSpace(dlo.Xbxs))
            //{
            //    MessageBox.Show("芯板形式不能为空");
            //    flag = false;
            //    return flag;
            //}

            if (string.IsNullOrWhiteSpace(dlo.Color))
            {
                MessageBox.Show("颜色不能为空");
                flag = false;
                return flag;
            }
            if (dlo.IsOld ==1) {
                if (string.IsNullOrWhiteSpace(dlo.OldColorId))
                {
                    MessageBox.Show("做旧颜色不能为空");
                    flag = false;
                    return flag;
                }
            }
            if (string.IsNullOrWhiteSpace(dlo.Num))
            {
                MessageBox.Show("数量不能为空");
                flag = false;
                return flag;
            }
            if (string.IsNullOrWhiteSpace(dlo.Direction))
            {
                MessageBox.Show("开孔方向不能为空");
                flag = false;
                return flag;
            }
            if (dlo.IsZh == 2) {
                if (string.IsNullOrWhiteSpace(dlo.XbTop)) {
                    MessageBox.Show("选择自定义中横，上芯板高度不能为空");
                    flag = false;
                    return flag;
                }
            }
            if (string.IsNullOrWhiteSpace(dlo.PackageId)) {
                MessageBox.Show("包装类别不能为空");
                flag = false;
                return flag;
            }
            return flag;
        }
        //装饰线条必填项检查
        private bool ValidateZsxtData(DetailOrder dlo)
        {
            bool flag = true;

            if (string.IsNullOrWhiteSpace(dlo.Danhao))
            {
                MessageBox.Show("单号不能为空");
                flag = false;
                return flag;
            }
            if (string.IsNullOrWhiteSpace(dlo.Mxbh))
            {
                MessageBox.Show("装饰线条编号不能为空");
                flag = false;
                return flag;
            }
            if (string.IsNullOrWhiteSpace(dlo.Gao))
            {
                MessageBox.Show("高不能为空");
                flag = false;
                return flag;
            }
            if (string.IsNullOrWhiteSpace(dlo.Color))
            {
                MessageBox.Show("颜色不能为空");
                flag = false;
                return flag;
            }
            if (dlo.IsOld == 1)
            {
                if (string.IsNullOrWhiteSpace(dlo.OldColorId))
                {
                    MessageBox.Show("做旧颜色不能为空");
                    flag = false;
                    return flag;
                }
            }
            if (string.IsNullOrWhiteSpace(dlo.Num))
            {
                MessageBox.Show("数量不能为空");
                flag = false;
                return flag;
            }
            return flag;
        }
        //条形码生成工具
        public static void GetBarcode(int height, int width, BarcodeLib.TYPE type, string code, out System.Drawing.Image image, string fileSaveUrl)
        {
            try
            {
                image = null;
                BarcodeLib.Barcode b = new BarcodeLib.Barcode();
                b.BackColor = System.Drawing.Color.White;//图片背景颜色
                b.ForeColor = System.Drawing.Color.Black;//条码颜色
                b.IncludeLabel = true;
                b.Alignment = BarcodeLib.AlignmentPositions.CENTER;
                b.LabelPosition = BarcodeLib.LabelPositions.BOTTOMCENTER;
                b.ImageFormat = System.Drawing.Imaging.ImageFormat.Jpeg;//图片格式
                System.Drawing.Font font = new System.Drawing.Font("verdana", 10f);//字体设置
                b.LabelFont = font;
                b.Height = height;//图片高度设置(px单位)
                b.Width = width;//图片宽度设置(px单位)
                image = b.Encode(type, code);//生成图片
                //image.Save(fileSaveUrl, System.Drawing.Imaging.ImageFormat.Jpeg);
            }
            catch (Exception ex)
            {
                image = null;
            }
        }
        //生成条形码
        public bool GenerateCode(DetailOrder dlo,string path,long did) {
            bool flag = true;
            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);
            }
            if (string.IsNullOrWhiteSpace(dlo.Num)) {
                MessageBox.Show("数量不能为空");
                return false;
            }
            List<Barcode> ls = new List<Barcode>();
            Bitmap bmp = null;
            //int m = int.Parse(dlo.Num);
            for (int i = 1; i <= int.Parse(dlo.Num); i++)
            {
                Barcode bc = new Barcode();
                System.Drawing.Image image;
                int width = 200, height = 80;
                string code = dlo.Danhao + dlo.Xh.ToString("00") + i.ToString("00");
                string fileSavePath = path + "\\" + code + ".jpg";
                //MessageBox.Show(AppDomain.CurrentDomain.BaseDirectory);
                //return;
                if (File.Exists(fileSavePath))
                    File.Delete(fileSavePath);
                GetBarcode(height, width, BarcodeLib.TYPE.CODE128, code, out image, fileSavePath);
              
                if (image == null) {
                    flag = false;
                    throw new Exception("生成条形码出现问题了");
                }
                //转成二进制字节
                bmp = new Bitmap(image);
                Byte[] imgBytes = BitmapToBytes(bmp);
                bc.Bitpath = Convert.ToBase64String(imgBytes);

                bc.Did = did.ToString();
                bc.Color = dlo.Color;
                bc.Danhao = dlo.Danhao;
                bc.ImagePath = fileSavePath;
                ls.Add(bc);
            }
            if(!dal.SaveBarCode(ls))flag=false;
            return flag;
        }
        //转换成二进制
        private byte[] BitmapToBytes(Bitmap Bitmap)
        {
            MemoryStream ms = null;
            try
            {
                ms = new MemoryStream();
                Bitmap.Save(ms, ImageFormat.Jpeg);
                byte[] byteImage = new Byte[ms.Length];
                byteImage = ms.ToArray();
                return byteImage;
            }
            catch (ArgumentNullException ex)
            {
                throw ex;
            }
            finally
            {
                ms.Close();
            }
        } 
        #endregion 自定义方法

        //复选框
        private void rbGlassNo_CheckedChanged(object sender, EventArgs e)
        {
            //dtGlassType=dicType.SpecialGlassListAll();
            //DataRow drGlassType = dtGlassType.NewRow();
            //dtGlassType.Rows.InsertAt(drGlassType,0);
            //this.cbGlassType.DataSource = dtGlassType;
            //this.cbGlassType.DisplayMember = "glasstype";
            //this.cbGlassType.ValueMember = "gid";
            if (this.gbGlass.Enabled)
            {
                if (this.rbGlassNo.Checked)
                {
                    dtGlassType = dicType.NormalGlassListAll();
                    DataRow drGlassType = dtGlassType.NewRow();
                    dtGlassType.Rows.InsertAt(drGlassType,0);
                    this.cbGlassType.DataSource = dtGlassType;
                    this.cbGlassType.DisplayMember = "glasstype";
                    this.cbGlassType.ValueMember = "gid";
                    this.cbGlassType.SelectedIndex = 1;

                    lbglassmust.Visible = false;
                    
                }else{
                    dtGlassType = dicType.SpecialGlassListAll();
                    this.cbGlassType.DataSource = dtGlassType;
                    this.cbGlassType.DisplayMember = "glasstype";
                    this.cbGlassType.ValueMember = "gid";

                    lbglassmust.Visible = true;
                }
            }
        }

        private void cbMxbh_DrawItem(object sender, DrawItemEventArgs e)
        {
            if (e.Index < 0)
            {
                return;
            }
            e.DrawBackground();
            e.DrawFocusRectangle();
            e.Graphics.DrawString(cbMxbh.GetItemText(cbMxbh.Items[e.Index]).ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds.X, e.Bounds.Y + 3);  
        }

        private void cbMxbh_TextChanged(object sender, EventArgs e)
        {
            //int index = this.cbMxbh.SelectedIndex;
            
           if (this.cbMxbh.SelectedIndex >= 0)
            {
                string mxbh = this.cbMxbh.SelectedValue.ToString();
                mxbh = mxbh.ToUpper();
                //MessageBox.Show(mxbh);
                DataRow[] drs = dtMxbh.Select("mxbh='" + mxbh + "'");
                if (drs.Length == 0)
                {
                    this.tbKxbh.Text = "";
                    this.tbXbmc.Text = "";
                    this.gbGlass.Enabled = false;
                    this.cbGlassType.Enabled = false;
                    return;
                }
                else if (drs.Length == 1)
                {
                    this.tbKxbh.Text = drs[0]["kxbh"].ToString();
                    this.tbXbmc.Text = drs[0]["xbmc"].ToString();
                    this.tbMenxingprice.Text = drs[0]["price"].ToString();
                    this.tbSpecial.Text = drs[0]["specialname"].ToString();
                    this.tbAddPrice.Text = drs[0]["addprice"].ToString();
                    this.tbIsSoft.Text = drs[0]["issoft"].ToString();
                    this.tbIsSpecial.Text = drs[0]["special"].ToString();
                    this.tbglass.Text = drs[0]["glass"].ToString();
                    if (drs[0]["glass"].ToString().Equals("0"))
                    {
                        this.cbGlassType.SelectedIndex = 0;
                        foreach (RadioButton rb in this.gbGlass.Controls)
                        {
                            if (rb.Tag.ToString() == "0")
                            {
                                rb.Checked = true;
                            }
                            else
                            {
                                rb.Checked = false;
                            }
                        }
                        this.gbGlass.Enabled = false;
                        this.cbGlassType.Enabled = false;
                    }
                    else
                    {
                        this.cbGlassType.SelectedIndex = 1;
                        foreach (RadioButton rb in this.gbGlass.Controls)
                        {
                            if (rb.Tag.ToString() == "0")
                            {
                                rb.Checked = true;
                            }
                            else
                            {
                                rb.Checked = false;
                            }
                        }
                        this.gbGlass.Enabled = true;
                        this.cbGlassType.Enabled = true;
                    }
                    DataTable dt = dal.GetExpression(drs[0]["kxbh"].ToString());
                    if (dt != null)
                    {
                        this.lbcare.Text = dt.Rows[0]["remarks"].ToString();
                    }
                    else
                    {
                        this.lbcare.Text = "";
                    }
                    if ("PB-PB01".Equals(mxbh))
                    {
                        this.lbxbcolor.Visible = false;
                        this.lbxbbq.Visible = false;
                        this.tbxbcolor.Visible = false;
                    }
                    else
                    {
                        this.lbxbcolor.Visible = true;
                        this.lbxbbq.Visible = true;
                        this.tbxbcolor.Visible = true;
                        
                    }
                    //根据门型获取另加装饰选项
                    DataTable dectable = dicType.GetOtherName(drs[0]["kxbh"].ToString());
                    if (dectable == null || dectable.Rows.Count <= 0)
                    {
                        this.lbOtherRed.Visible = false;
                        this.lbOther.Visible = false;
                        this.lbOther.Text = "";
                        this.cbOther.Visible = false;
                        this.cbOther.DataSource = null;
                    }
                    else
                    {
                        object o = dectable.Rows[0]["decname"];
                        if (o == DBNull.Value || o == null)
                        {
                            this.lbOtherRed.Visible = false;
                            this.lbOther.Visible = false;
                            this.lbOther.Text = "";
                            this.cbOther.Visible = false;
                            this.cbOther.DataSource = null;
                        }
                        else
                        {
                            this.lbOtherRed.Visible = true;
                            this.lbOther.Visible = true;
                            this.lbOther.Text = o + ":";
                            this.cbOther.Visible = true;
                           
                            otherDetail = dicType.GetOtherDetail(drs[0]["kxbh"].ToString(), dectable.Rows[0]["oid"].ToString());
                            otherDetail.Rows.InsertAt(otherDetail.NewRow(), 0);
                            this.cbOther.DataSource = otherDetail;
                        }
                    }

                }
                else
                {
                    MessageBox.Show("出现重复值");
                    return;
                }
            }
        }
        //长度数字校验
        private void tbCd_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '.' && this.tbCd.Text.IndexOf(".") != -1)
            {
                e.Handled = true;
            }

            if (!((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == '.' || e.KeyChar == 8))
            {
                e.Handled = true;
            }  
        }
        //高数字验证
        private void tbGao_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '.' && this.tbGao.Text.IndexOf(".") != -1)
            {
                e.Handled = true;
            }

            if (!((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == '.' || e.KeyChar == 8))
            {
                e.Handled = true;
            }  
        }
        //厚数字验证
        private void tbHou_KeyPress(object sender, KeyPressEventArgs e)
        {
            //if (e.KeyChar == '.' && this.tbHou.Text.IndexOf(".") != -1)
            //{
            //    e.Handled = true;
            //}

            //if (!((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == '.' || e.KeyChar == 8))
            //{
            //    e.Handled = true;
            //}  
        }
        //宽数字验证
        private void tbKuan_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '.' && this.tbKuan.Text.IndexOf(".") != -1)
            {
                e.Handled = true;
            }

            if (!((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == '.' || e.KeyChar == 8))
            {
                e.Handled = true;
            }  
        }
        //其他费用数字验证
        private void tbOtherPrice_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '.' && this.tbOtherPrice.Text.IndexOf(".") != -1)
            {
                e.Handled = true;
            }

            if (!((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == '.' || e.KeyChar == 8))
            {
                e.Handled = true;
            }  
        }
        //数量验证
        private void tbNum_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == '.' || e.KeyChar == 8))
            {
                e.Handled = true;
            }  
        }

        private void cbZsxt_TextChanged(object sender, EventArgs e)
        {
            if (this.cbZsxt.SelectedIndex > 0)
            {
                string zsxt = this.cbZsxt.SelectedValue.ToString();
                DataRow[] drs = dtZsxt.Select("zsbh='" + zsxt + "'");
                if (drs.Count() > 0)
                {
                    this.tbXtprice.Text = drs[0]["zsdj"].ToString();
                    this.tbIszt.Text = drs[0]["zslb"].ToString();
                    if (drs[0]["zslb"].ToString().Equals("1"))
                    {
                        this.tbCd.Text = drs[0]["xtcd"].ToString();
                        this.tbCd.Enabled = false;
                    }
                    else 
                    {
                        this.tbCd.Enabled = true;
                    }
                }
            }
            else {
                this.tbCd.Enabled = true;
            }
        }

        private void rbOldYes_CheckedChanged(object sender, EventArgs e)
        {
            if (rbOldYes.Checked)
            {
                this.cbXbzjColor.DataSource = dtZsxtZj;
                this.cbXbzjColor.DisplayMember = "mcolor";
                this.cbXbzjColor.ValueMember = "mid";

                this.cbXbzjColor.Enabled = true;
                lbzj.Visible = true;

            }
            else {
                this.cbXbzjColor.Enabled = false;
                this.cbXbzjColor.SelectedIndex = 0;
                lbzj.Visible = false;
            }
        }

        private void tbTopHeight_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == '.' && this.tbOtherPrice.Text.IndexOf(".") != -1)
            {
                e.Handled = true;
            }

            if (!((e.KeyChar >= 48 && e.KeyChar <= 57) || e.KeyChar == '.' || e.KeyChar == 8))
            {
                e.Handled = true;
            }  
        }
        //中横自定义激活状态
        private void rbZhDefined_Click(object sender, EventArgs e)
        {
            if (rbZhDefined.Checked)
            {
                this.tbTopHeight.Enabled = true;
                this.tbTopHeight.Text = this.tbxbtop.Text;

                lbtopmust.Visible = true;
            }
            else {
                this.tbTopHeight.Enabled = false;
                this.tbxbtop.Text = this.tbTopHeight.Text;
                lbtopmust.Visible = false;
            }
        }

        private void rbZhNo_Click(object sender, EventArgs e)
        {
            if (rbZhNo.Checked) {
                this.tbTopHeight.Text = "";
                this.tbTopHeight.Enabled = false;
                lbtopmust.Visible = false;
            }
        }

        private void brZhYes_Click(object sender, EventArgs e)
        {
            if (this.brZhYes.Checked)
            { 
                this.tbTopHeight.Text = "";
                this.tbTopHeight.Enabled = false;
                lbtopmust.Visible = false;
            }
        }
        //包装下拉
        private void cbpackage_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.cbpackage.SelectedIndex >= 0) {
                string packageName = this.cbpackage.Text.Trim();
                if (dtPackage.Rows.Count > 0) {
                    DataRow[] drs = this.dtPackage.Select("ptype='"+packageName+"'");
                    if (drs.Length == 1)
                    {
                        this.tbpackageprice.Text = drs[0]["price"].ToString();
                        this.tbBzbz.Text = drs[0]["ptype"].ToString();
                    }
                    else {
                        this.tbpackageprice.Text = "";
                        this.tbBzbz.Text = "无";
                    }
                }
               // MessageBox.Show(this.cbpackage.SelectedValue.ToString() +"--"+ this.cbpackage.Text.ToString());
            }
        }
        //边框颜色变化 带动芯板颜色
        private void cbColor_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (this.cbColor.SelectedIndex >= 0)
            {
                string mxbh = this.cbMxbh.SelectedValue == null ? "" : this.cbMxbh.SelectedValue.ToString();
                string cbColor = this.cbColor.Text.Trim();
                if (xbColorFlag && !mxbh.Equals("PB-PB01"))
                {
                    this.tbxbcolor.Text = cbColor;
                }
                // MessageBox.Show(this.cbpackage.SelectedValue.ToString() +"--"+ this.cbpackage.Text.ToString());
            }
        }
        //下拉另加装饰项的限制提示
        private void cbOther_SelectedIndexChanged(object sender, EventArgs e)
        {
            //otherDetail
            if (this.cbOther.SelectedIndex >= 0&&otherDetail.Rows.Count>0) 
            {
                string oid = this.cbOther.SelectedValue.ToString();
                if (!string.IsNullOrWhiteSpace(oid))
                {
                    DataRow[] drs = otherDetail.Select("oid='" + oid + "'");
                    if (drs != null && drs.Length > 0 && !string.IsNullOrWhiteSpace(drs[0]["limitMx"].ToString()))
                    {
                        string limtmx = drs[0]["limitMx"].ToString();
                        string[] ls = limtmx.Split(',');
                        if (!string.IsNullOrWhiteSpace(this.cbMxbh.SelectedValue.ToString()) && ls.Contains(this.cbMxbh.SelectedValue.ToString()))
                        {
                            MessageBox.Show("此门型不适应此选项，请重新选择");
                            this.cbOther.SelectedIndex = 0;
                        }
                    }
                }
            }
        }
        //边框颜色变化 带动芯板颜色
        private void cbColor_TextChanged(object sender, EventArgs e)
        {
            //if (this.cbColor.SelectedIndex >= 0)
            //{
            //    string cbColor = this.cbColor.Text.Trim();
            //    this.tbxbcolor.Text = cbColor;
            //    // MessageBox.Show(this.cbpackage.SelectedValue.ToString() +"--"+ this.cbpackage.Text.ToString());
            //}
        }
        //边框颜色变化 带动芯板颜色
        private void cbColor_SelectionChangeCommitted(object sender, EventArgs e)
        {
            xbColorFlag = true;
            //if (this.cbColor.SelectedIndex >= 0)
            //{
            //    string cbColor = this.cbColor.SelectedText.Trim();
            //    this.tbxbcolor.Text = cbColor;
            //    //MessageBox.Show(this.cbpackage.SelectedValue.ToString() + "--" + this.cbpackage.Text.ToString());
            //}
        }

       
       
    }
}
